package com.mk.common;

import java.awt.geom.Point2D;
import java.util.List;

/**
 * Created by yanzhiping on 2017/8/14.
 */
public class Tools {

    /**
     * 返回一个点是否在一个多边形区域内
     * 实际使用用来判断是否在地理围栏内
     * @param point
     * @param polygon
     * @return
     */
    public static boolean checkPointInRange(Point2D.Double point, List<Point2D.Double> polygon) {
        java.awt.geom.GeneralPath p = new java.awt.geom.GeneralPath();
        Point2D.Double first = polygon.get(0);
        p.moveTo(first.x, first.y);
        polygon.remove(0);
        for (Point2D.Double d : polygon) {
            p.lineTo(d.x, d.y);
        }
        p.lineTo(first.x, first.y);
        p.closePath();
        return p.contains(point);

    }
}
